#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "php.h"
#include "php_openal.h"


//. module init.
PHP_MINIT_FUNCTION(openal) {

	zend_class_entry ce;	

	openal_init();

	//. register OpenAL.
	INIT_CLASS_ENTRY(ce, "OpenAL", openal_class_functions);
	openal_ce = zend_register_internal_class(&ce TSRMLS_CC);
	openal_ce->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
	zend_declare_class_constant_long(openal_ce,"SOURCE_STATIC",(sizeof("SOURCE_STATIC")-1),AL_STATIC TSRMLS_CC);
	zend_declare_class_constant_long(openal_ce,"SOURCE_STREAMING",(sizeof("SOURCE_STREAMING")-1),AL_STREAMING TSRMLS_CC);
	zend_declare_class_constant_long(openal_ce,"SOURCE_UNDETERMINED",(sizeof("SOURCE_UNDETERMINED")-1),AL_UNDETERMINED TSRMLS_CC);
	zend_declare_class_constant_long(openal_ce,"STATE_INITIAL",(sizeof("STATE_INITIAL")-1),AL_INITIAL TSRMLS_CC);
	zend_declare_class_constant_long(openal_ce,"STATE_PLAYING",(sizeof("STATE_PLAYING")-1),AL_PLAYING TSRMLS_CC);
	zend_declare_class_constant_long(openal_ce,"STATE_PAUSED",(sizeof("STATE_PAUSED")-1),AL_PAUSED TSRMLS_CC);
	zend_declare_class_constant_long(openal_ce,"STATE_STOPPED",(sizeof("STATE_STOPPED")-1),AL_STOPPED TSRMLS_CC);
	memcpy(&obj_openal_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));



	//. register OpenALBuffer.
	INIT_CLASS_ENTRY(ce, "OpenALBuffer", openalbuffer_functions);
	openalbuffer_ce = zend_register_internal_class(&ce TSRMLS_CC);
	openalbuffer_ce->create_object = obj_openal_buffer_new;
	memcpy(&obj_openal_buffer_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
	obj_openal_buffer_handlers.read_property = obj_openal_buffer_read_property;
	obj_openal_buffer_handlers.write_property = obj_openal_buffer_write_property;



	//. register OpenALSource.
	INIT_CLASS_ENTRY(ce, "OpenALSource", openalsource_functions);
	openalsource_ce = zend_register_internal_class(&ce TSRMLS_CC);
	openalsource_ce->create_object = obj_openal_source_new;
	zend_declare_property_null(openalsource_ce, "buffer", (sizeof("buffer")-1), ZEND_ACC_PUBLIC TSRMLS_CC);
	memcpy(&obj_openal_source_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
	obj_openal_buffer_org_write_property = obj_openal_source_handlers.write_property;
	obj_openal_source_handlers.read_property = obj_openal_source_read_property;
	obj_openal_source_handlers.write_property = obj_openal_source_write_property;
}

PHP_MSHUTDOWN_FUNCTION(openal) {

	openal_shutdown();

}

PHP_MINFO_FUNCTION(openal) {
	php_info_print_table_start();
	php_info_print_table_row(2, "OpenAL Support", "enabled");
	php_info_print_table_end();
}

zend_module_entry openal_module_entry = {
	STANDARD_MODULE_HEADER,
	PHP_OPENAL_EXTNAME,
	openal_functions,
	PHP_MINIT(openal),
	PHP_MSHUTDOWN(openal),
	NULL,
	NULL,
	PHP_MINFO(openal),
	PHP_OPENAL_VERSION,
	STANDARD_MODULE_PROPERTIES
};

#ifdef COMPILE_DL_OPENAL
ZEND_GET_MODULE(openal)
#endif

